"""
Base animation engine interface.

Defines the interface for all animation engines.
"""

from abc import ABC, abstractmethod
from typing import Dict, List, Any, Optional
from ...parser.content_types import AnimatedContent, ContentNode, Section


class BaseAnimationEngine(ABC):
    """Base class for animation engines."""
    
    def __init__(self, config: Optional[Dict[str, Any]] = None):
        """Initialize the animation engine."""
        self.config = config or {}
    
    @abstractmethod
    def render_animated_content(self, animated_content: AnimatedContent, 
                              context: Optional[Dict[str, Any]] = None) -> str:
        """
        Render animated content to the target format.
        
        Args:
            animated_content: The animated content to render
            context: Additional context for rendering
            
        Returns:
            Rendered content string
        """
        pass
    
    @abstractmethod
    def render_section(self, section: Section, 
                      animations: List[AnimatedContent],
                      context: Optional[Dict[str, Any]] = None) -> str:
        """
        Render a complete section with animations.
        
        Args:
            section: The section to render
            animations: List of animations for this section
            context: Additional context for rendering
            
        Returns:
            Rendered section string
        """
        pass
    
    @abstractmethod
    def generate_animation_timeline(self, animations: List[AnimatedContent]) -> Dict[str, Any]:
        """
        Generate animation timeline for a set of animations.
        
        Args:
            animations: List of animations to timeline
            
        Returns:
            Timeline configuration
        """
        pass
    
    @abstractmethod
    def get_supported_features(self) -> List[str]:
        """
        Get list of supported animation features.
        
        Returns:
            List of feature names
        """
        pass
    
    def validate_config(self) -> bool:
        """
        Validate engine configuration.
        
        Returns:
            True if configuration is valid
            
        Raises:
            ConfigurationError: If configuration is invalid
        """
        return True
    
    def get_engine_info(self) -> Dict[str, Any]:
        """
        Get information about this animation engine.
        
        Returns:
            Engine information dictionary
        """
        return {
            'name': self.__class__.__name__,
            'supported_features': self.get_supported_features(),
            'config': self.config
        }


class AnimationEngineError(Exception):
    """Base exception for animation engine errors."""
    pass


class ConfigurationError(AnimationEngineError):
    """Raised when engine configuration is invalid."""
    pass


class RenderingError(AnimationEngineError):
    """Raised when content rendering fails."""
    pass